#include <iostream>
#include <unistd.h>
#include <time.h>
#include "ThreadPool.hpp"
#include "Task.hpp"
using namespace std;

int main()
{
    
    // ThreadPool<Task>* tp = new ThreadPool<Task>(5);
    // tp->Start();

    std::cout << "process runn..." << std::endl;
    ThreadPool<Task>::GetInstance()->Start();   // 懒汉单例启动线程池
    srand(time(nullptr) ^ getpid());
    
    while (true)
    {
        // 1. 构建任务
        int x = rand() % 10 + 1;   
        usleep(10);
        int y = rand() % 5;
        char op = opers[rand() % opers.size()];
        Task t(x, y, op);
        // tp->Push(t);
        ThreadPool<Task>::GetInstance()->Push(t);

        // 2. 分配任务
        cout << "main thread make task: " << t.GetTask() << endl;
        sleep(1);
    }
    

    return 0;
}